package com.template.entity.markdown;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;

import static com.template.utlis.StringCommons.*;
import static com.template.utlis.StringCommons.TagEnum.COLUMN;

/**
 * @author wangqi
 * @date 2024-01-18 16:03
 */
public class Column {
    private JSONObject column;
    private JSONArray elements;

    public Column() {
        column = new JSONObject();
        elements = new JSONArray();
        column.put(TAG, COLUMN.getValue());
    }

    public static Column create() {
        return new Column();
    }

    public static Column createDefault(){
        return Column.create().width(WeightEnum.FIVE).verticalAlign(VerticalAlignEnum.CENTER);
    }

    public JSONObject build() {
        column.put(ELEMENTS,elements);
        return column;
    }

    public Column width(WeightEnum weightEnum) {
        if (weightEnum != null) {
            column.put(WIDTH, WEIGHTED);
            column.put(WEIGHT, weightEnum.getValue());
        }
        return this;
    }

    public Column verticalAlign(VerticalAlignEnum verticalAlignEnum) {
        if (verticalAlignEnum != null) {
            column.put(VERTICAL_ALIGN, verticalAlignEnum.getValue());
        }
        return this;
    }

    public Column addUndefinedElement(JSONObject element) {
        if (element != null) {
            elements.add(element);
        }
        return this;
    }

    public Column addMarkdownElement(MarkdownElement element) {
        if (element != null) {
            elements.add(element.build());
        }
        return this;
    }

}
